import request from '../utils/request';

// 登录
export const userLogin = form => {
    return request({
        url: '/user/login',
        method: 'post',
        data: form
    });
};

// 注册
export const register = form => {
    return request({
        url: '/user/register',
        method: 'post',
        data: form
    });
};

// 获取文章信息列表
export const getArticleList = query => {
    return request({
        url: '/article/list/',
        method: 'get',
        params: query
    });
};

// 获取文章基本数据信息
export const getArticleBase = () => {
    return request({
        url: '/article/base',
        method: 'get',
    });
};


// 获取文章信息
export const getArticle = query => {
    return request({
        url: '/article/detail/' + query,
        method: 'get'
    });
};

// 发布文章
export const addArticle = form => {
    return request({
        url: '/article/',
        method: 'post',
        data: form
    });
};

// 修改文章信息
export const modifyArticle = form => {
    return request({
        url: '/article/',
        method: 'put',
        data: form
    });
};

// 获取文章类别信息列表
export const getTypeList = () => {
    return request({
        url: '/type/',
        method: 'get'
    });
};


// 获取日程信息列表
export const getScheduleList = (query) => {
    return request({
        url: '/schedule',
        method: 'get',
        params: query
    });
};

// 添加日程
export const addSchedule = (form) => {
    return request({
        url: '/schedule/',
        method: 'post',
        data: form
    });
};

// 修改日程
export const updateSchedule = (form) => {
    return request({
        url: '/schedule/',
        method: 'put',
        data: form
    });
};

// 修改日程
export const deleteSchedule = (id) => {
    return request({
        url: '/schedule/' + id,
        method: 'delete'
    });
};

export const dateConvert = (date, begin) => {
    if (!date) return "";
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    if (begin) {
        return year + '/' + month + '/' + day + " 00:00:00";
    } else {
        return year + '/' + month + '/' + day + " 23:59:59";
    }
};